import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
  path: '/login',
  component: () => import('@/views/login/index'),
  hidden: true
},

{
  path: '/404',
  component: () => import('@/views/404'),
  hidden: true
},
{
  path: '/',
  component: Layout,
  redirect: '/dashboard',
  children: [{
    path: 'dashboard',
    name: '首页',
    component: () => import('@/views/dashboard/index'),
    meta: {
      title: '首页',
      icon: 'dashboard',
      affix: true
    }
  }]
},
{
  path: '/grade/jichupeizhi',
  component: Layout,
  meta: {
    title: '基础配置',
    icon: 'el-icon-s-help'
  },
  children: [{
    path: 'caidanguanli',
    name: '菜单管理',
    meta: {
      title: '菜单管理',
      icon: 'table'
    },
    component: () => import('@/views/grade/jichupeizhi/caidanguanli')
  },
  {
    path: 'quanjucanshu',
    name: '全局参数',
    meta: {
      title: '全局参数',
      icon: 'table'
    },
    component: () => import('@/views/grade/jichupeizhi/quanjucanshu')
  },
  {
    path: 'shujuzidain',
    name: '数据字典',
    meta: {
      title: '数据字典',
      icon: 'table'
    },
    component: () => import('@/views/grade/jichupeizhi/shujuzidian')
  }
  ]
},
{
  path: '/grade/yonghuguanli',
  component: Layout,
  meta: {
    title: '用户管理',
    icon: 'el-icon-s-help'
  },
  children: [{
    path: 'xitongyonghu',
    name: '系统用户',
    meta: {
      title: '系统用户',
      icon: 'table'
    },
    component: () => import('@/views/grade/yonghuguanli/xitongyonghu')
  }, {
    path: 'jueseguanli',
    name: '角色管理',
    meta: {
      title: '角色管理',
      icon: 'table'
    },
    component: () => import('@/views/grade/yonghuguanli/jueseguanli')
  },

  {
    path: 'zuzhiguanli',
    name: '组织管理',
    meta: {
      title: '组织管理',
      icon: 'table'
    },
    component: () => import('@/views/grade/yonghuguanli/zuzhiguanli')
  }
  ]
},
{
  path: '/grade/xunihaoguanli',
  component: Layout,
  meta: {
    title: '虚拟号管理',
    icon: 'el-icon-s-help'
  },
  children: [{
    path: 'xunihaodongtaibangding',
    name: '虚拟号动态绑定',
    meta: {
      title: '虚拟号动态绑定',
      icon: 'table'
    },
    component: () => import('@/views/grade/xunihaoguanli/xunihaodongtaibangding')
  },
  {
    path: 'bangdingjiluchaxun',
    name: '绑定记录查询',
    meta: {
      title: '绑定记录查询',
      icon: 'table'
    },
    component: () => import('@/views/grade/xunihaoguanli/bangdingjiluchaxun')
  }
  ]
},
{
  path: '/grade/tonghuajilu',
  component: Layout,
  meta: {
    title: '通话记录',
    icon: 'el-icon-s-help'
  },
  alwaysShow: true,
  children: [{
    path: 'tonghuajilu',
    name: '通话记录',
    meta: {
      title: '通话记录',
      icon: 'table'
    },
    component: () => import('@/views/grade/tonghuajilu')
  }
  ]
},
{
  path: '/grade/luyinjilu',
  component: Layout,
  meta: {
    title: '通话记录',
    icon: 'el-icon-s-help'
  },
  alwaysShow: true,
  children: [{
    path: 'luyinjilu',
    name: '录音记录与转文字',
    meta: {
      title: '录音记录与转文字',
      icon: 'table'
    },
    component: () => import('@/views/grade/luyinjilu')
  }
  ]
},
{
  path: '/grade/zhinengfenxi',
  component: Layout,
  meta: {
    title: '智能分析',
    icon: 'el-icon-s-help'
  },
  alwaysShow: true,
  children: [{
    path: 'zhinengfenxi',
    name: '通话情感分析记录',
    meta: {
      title: '通话情感分析记录',
      icon: 'table'
    },
    component: () => import('@/views/grade/zhinengfenxi')
  }
  ]
},
{
  path: '/grade/duanxinjilu',
  component: Layout,
  meta: {
    title: '短信记录',
    icon: 'el-icon-s-help'
  },
  alwaysShow: true,
  children: [{
    path: 'duanxinjilu',
    name: '短信记录',
    meta: {
      title: '短信记录',
      icon: 'table'
    },
    component: () => import('@/views/grade/duanxinjilu')
  }
  ]
},
{
  path: '/grade/shujutongji',
  component: Layout,
  meta: {
    title: '数据统计',
    icon: 'el-icon-s-help'
  },
  children: [{
    path: 'xunihaotongjifenxibaobiao',
    name: '虚拟号统计分析报表',
    meta: {
      title: '虚拟号统计分析报表',
      icon: 'table'
    },
    component: () => import('@/views/grade/shujutongji/xunihaotongjifenxibaobiao')
  },
  {
    path: 'smsstatistics',
    name: '短信统计分析',
    meta: {
      title: '短信统计分析',
      icon: 'table'
    },
    component: () => import('@/views/grade/shujutongji/SMSStatistics')
  },
  {
    path: 'calllog',
    name: '通话记录统计分析',
    meta: {
      title: '通话记录统计分析',
      icon: 'table'
    },
    component: () => import('@/views/grade/shujutongji/CallLog')
  }
  ]
},
{
  path: '/grade/abnormal',
  component: Layout,
  meta: {
    title: '异常统计',
    icon: 'el-icon-s-help'
  },
  children: [{
    path: 'unbanding',
    name: '零数据明细',
    meta: {
      title: '零数据明细',
      icon: 'table'
    },
    component: () => import('@/views/grade/abnormal/unbanding')
  },
  {
    path: 'zerodata',
    name: '未绑定明细',
    meta: {
      title: '未绑定明细',
      icon: 'table'
    },
    component: () => import('@/views/grade/abnormal/zerodata')
  }
  ]
},
{
  path: '/grade/map',
  component: Layout,
  meta: {
    title: 'map',
    icon: 'el-icon-s-help'
  },
  alwaysShow: true,
  children: [{
    path: 'map',
    name: 'map',
    meta: {
      title: 'map',
      icon: 'table'
    },
    component: () => import('@/views/grade/map')
  }
  ]
},
{
  path: '/grade/map2',
  component: Layout,
  meta: {
    title: 'map2',
    icon: 'el-icon-s-help'
  },
  alwaysShow: true,
  children: [{
    path: 'map2',
    name: 'map2',
    meta: {
      title: 'map2',
      icon: 'table'
    },
    component: () => import('@/views/grade/map2')
  }
  ]
},
{
  path: '/grade/map1',
  component: Layout,
  meta: {
    title: 'map1',
    icon: 'el-icon-s-help'
  },
  alwaysShow: true,
  children: [{
    path: 'map1',
    name: 'map1',
    meta: {
      title: 'map1',
      icon: 'table'
    },
    component: () => import('@/views/grade/map1')
  }
  ]
},

// 404 page must be placed at the end !!!
{
  path: '*',
  redirect: '/404',
  hidden: true
}
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
